package com.example.switchbutton;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

/**
 * Created by Administrator on 2018/6/17.
 */

public class CircularView extends View {

    private int width;
    private int height;
    private  Paint paint;

    public CircularView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public CircularView(Context context) {
        super(context);
    }

    public CircularView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();

    }



    private void initView() {
        paint = new Paint();
        paint.setColor(Color.parseColor("#ff0000"));
    }



    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        width=getMeasuredWidth();
        height=getMeasuredHeight();
        Log.e("CircularView", "width=="+width+",,height=="+height);
        canvas.drawCircle(width/2,height/2,width>height? height/2 : width/2,paint);
    }
}
